package de.tabuma.formcreator.formstructur.logik;

import de.tabuma.formcreator.logik.*;
import de.tabuma.formcreator.entity.*;

import java.util.*;
import java.util.logging.*;

/**
 * @author $Author: $
 * @version $Revision: $
 * @since $Date: $
 */
public class FormStrukturFacade {

    private static final Logger log = Logger.getLogger(FormStrukturFacade.class.getName());

    public static void createFormStructurWithoutChoiceAllSequence(FormStructur formStructur,FormManager formManager) {
        for(int i=0;i<formStructur.getFormStructur().size();i++) {
            FormStructur formStructur1 = formStructur.getFormStructur().get(i);
            FormGroup formGroup = null;
            if(!formStructur1.isSimpleType()) {
                if(formStructur1.isAll()) {
                    formGroup = FormGroupFactory.createFormTypeAll();
                }
                if(formStructur1.isChoice()) {
                    formGroup = FormGroupFactory.createFormTypeChoice();
                }
                if(formStructur1.isSequence()) {
                    formGroup = FormGroupFactory.createFormTypeSequence();
                }
                if(formGroup!=null) {
                    for(int l=0;l<formStructur1.getFormStructur().size();l++) {
                        FormStructur formStructur2 = formStructur1.getFormStructur().get(l);
                        formStructur2.setHeadStructur(formStructur);
                        formGroup.getFormStructurList().add(formStructur2);
                        formStructur.getFormStructur().add(formStructur2);
                    }
                    formStructur.getFormStructur().remove(i);
                    formManager.getFormGroupList().add(formGroup);
                    i--;
                }
                else {
                    createFormStructurWithoutChoiceAllSequence(formStructur1,formManager);
                }
            }
        }
    }
}
